<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>制作12小时进制的时钟</title>
</head>
<body>
    <div id="myclock"></div> 
    <script type="text/javascript">
        function clock_12h()
        {
            var today = new Date(); 
            var year = today.getFullYear();
            var month = today.getMonth()+1;
            var date = today.getDate();
            var hour = today.getHours();  
            var minute = today.getMinutes();
            var second = today.getSeconds();
        
            var apm="AM"; 
            if (hour>12) 
            {
                hour=hour-12;
                apm="PM"  ;
            }
            var weekday = 0;
            switch(today.getDay()){
                case 0:
                    weekday = "星期日";
                    break;
                case 1:
                    weekday = "星期一";
                    break;
                case 2:
                    weekday = "星期二";
                    break;
                case 3:
                    weekday = "星期三";
                    break;
                case 4:
                    weekday = "星期四";
                    break;
                case 5:
                    weekday = "星期五";
                    break;
                case 6:
                    weekday = "星期六";
                    break;
                }
         
                
                document.getElementById("myclock").innerHTML="<h2>你好，现在是北京时间：</h2><h2>"+year+"年"+month+"月"+date+"日&nbsp;"+hour+":"+minute+":"+second+"&nbsp;"+apm+"&nbsp;"+weekday+"</h2>";
            }
        
        var myTime = setInterval("clock_12h()",1000); 
    </script>      
</body>
</html>